package com.dundun.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dundun.annotation.AuthCheck;
import com.dundun.common.utils.Ajax;
import com.dundun.domain.Internship;
import com.dundun.service.InternshipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "岗位相关接口")
@RequestMapping("/")
@RestController
public class InternshipController {
    @Resource
    private InternshipService internshipService;

    @ApiOperation(value = "获取岗位信息列表")
    @GetMapping("/GetInternshipInfo")
    @AuthCheck
    public Ajax GetInternshipInfo() {
        List<Internship> allInternship = internshipService.list(new QueryWrapper<Internship>().orderByDesc("publish_time"));
        return Ajax.success().put("data", allInternship);
    }

    @ApiOperation(value = "分页获取岗位信息列表")
    @GetMapping("/GetInternshipInfoByPage")
    public Ajax GetInternshipInfoByPage() {
        return Ajax.success().put("data", "the return data...");
    }


    @ApiOperation(value = "添加岗位信息")
    @PostMapping("/PostInternship")
    @AuthCheck
    public Ajax PostInternship(Internship internship) {

        if (internshipService.addInternship(internship) > 0) {
            return Ajax.success("添加成功");
        } else {
            return Ajax.error("添加失败");
        }
    }

    @ApiOperation(value = "获取指定岗位的详细信息")
    @GetMapping("/GetInternshipDetail")
    @AuthCheck
    public Ajax GetInternshipDetail(int internshipId) {
        Internship internship = internshipService.getById(internshipId);
        return Ajax.success().put("data", internship);
    }

    @ApiOperation(value = "获取我发布的岗位信息列表")
    @GetMapping("/GetMyInternship")
    @AuthCheck
    public Ajax GetMyInternship(int userId) {
        System.out.println(userId);
        List<Internship> worklist = internshipService.list(
                new QueryWrapper<Internship>().eq("user_id", userId)
        );
        return Ajax.success().put("data", worklist);
    }

    @ApiOperation(value = "分页获取我发布的岗位信息列表")
    @GetMapping("/GetMyInternshipByPage")
    public Ajax GetMyInternshipByPage(int userId) {
        return Ajax.success().put("data", "the return data...");
    }

    @ApiOperation(value = "删除指定岗位信息")
    @PostMapping("/DeleteInternship")
    @AuthCheck
    public Ajax DeleteInternship(int internshipId) {
        if (internshipService.removeById(internshipId)) {
            return Ajax.success("删除成功");
        } else {
            return Ajax.error("删除失败");
        }
    }

    @ApiOperation(value = "通过关键字搜索分页获取岗位信息列表")
    @GetMapping("/GeyInternshipBySearch")
    public Ajax SearchInternshipByPage(String keyWord) {
        return Ajax.success().put("data", "the return data...");
    }

    @ApiOperation(value = "通过岗位类别分页获取岗位信息列表")
    @GetMapping("/GeyInternshipByType")
    public Ajax GeyInternshipByType(String type) {
        return Ajax.success().put("data", "the return data...");
    }

    @ApiOperation(value = "通过实习地点分页获取岗位信息列表")
    @GetMapping("/GeyInternshipByCity")
    public Ajax GeyInternshipByCity(String city) {
        return Ajax.success().put("data", "the return data...");
    }
}
